; (function ($) {
	$.req = {
		get: function(url, d, success){
			this.request(url, d, 'GET', success);
		},
		post: function(url, d, success){
			this.request(url, d, 'POST', success);
		},
		'delete': function(url, d, success){
			this.request(url, d, 'DELETE', success);
		},
		put: function(url, d, success){
			this.request(url, d, 'PUT', success);
		},
		request: function(u, d, type, successCallback){
			let token = (localStorage.AccessToken || '');
			$.ajax({
				'url': u,
				'data':d,
				'type': (type || 'GET'),
				beforeSend: function(xhr) {
				    xhr.setRequestHeader('x-access-token', token);
				},
				success: function( r, status, xhr){
					var newtoken = xhr.getResponseHeader('x-access-token');
					if (newtoken) {
						localStorage.AccessToken = newtoken;
					}
				    successCallback(r);
					
				},
				error: function (xhr, s, e) {
				    if (xhr.status === 401) {
				        //登录
				        location.href = '/';
				        return;
				    }
				    if (xhr.status === 400) {
				        console.log('' + xhr.responseJSON.message);
				        $.ui.notice({ 'text': xhr.responseJSON.message, 'type':'warning' });
				        return;
				    }
				    $.ui.notice({ 'text': xhr.responseJSON.message, 'type': 'error' });
				    console.error('请求出错：' + u);
				}
			});
		}
	}
})(jQuery);